package com.haruhi.example;

import com.haruhi.ws.server.HandshakeInterceptor;
import com.haruhi.ws.server.HttpRequest;
import com.haruhi.ws.server.HttpResponse;
import io.undertow.util.HeaderMap;
import io.undertow.util.HeaderValues;

public class MyHandshakeInterceptor implements HandshakeInterceptor {


    @Override
    public boolean handshake(HttpRequest request, HttpResponse response) {
        System.out.println("自定义握手拦截器 收到握手："+request.getHostAndPort());
        HeaderMap requestHeaders = request.getRequestHeaders();
        HeaderValues token = requestHeaders.get("token");
        if(token != null && !token.isEmpty()){
            if(token.contains("1234")){
                return true;
            }
        }
        response.setStatusCode(403);
        return false;
    }
}
